<?php
/**
 * View ASSOCIA CONTATTI A LOCATION LaFabbrica.org
 * 
 * @author     luigi.pastore (gigi@la-fabbrica.org)
 * @created    17-mag-2011
 * @package    LaFabbrica
 * @copyright  Copyright (c) 2011 Luigi Pastore
 */
?>
<script type="text/javascript">
    //<![CDATA[
     
    function selectable(){
	$('a[id^="link-contact"]').click(function(){
         var id = $(this).attr('id');
            $('#selected_contacts').load('/admin/ajax/select/addcontactlocation/id/'+id.substr(13,id.length),
            unselectable // CallBack
         )})
     };

    function unselectable(){
        $('a[id^="unlink-contact"]').click(function(){
            var id = $(this).attr('id');
            $('#selected_contacts').load('/admin/ajax/select/remcontactlocation/id/'+id.substr(15,id.length),
            unselectable // CallBack
        );
    })};
     
    $(document).ready(function()
    {
        var paginator =	$('#contacts').pagination({
	    'targetUrl' : '/admin/ajax/list/contactsmini',
	    'orderField' : 'contact_name',
	    'orderDir' : 'asc'
	},selectable // CallBack
        );

	$("#new").fancybox({
	    'type' : 'ajax',
	    'showCloseButton' : false
	});
        
        $("#salva").click(function() {
          $('#form-invia').submit();
//          return false;
        });
	
	// Lancio unselectable per i contatti eventualmente già presenti...
	unselectable();
    });

    //]]>
</script>
<div class="info">
    <h2>Contatti di <?php echo $this->data['location_name'] ?></h2>
    <div>Per inserire un nuovo post...</div>
    <div>I campi contrassegnati da <span class="req">*</span> sono obbligatori!</div>
</div>
<div id="detailTableLeft">
    <form>
	<ul>
	    <li id="fo2li107" class="likert col2">
		<table cellspacing="0">
		    <caption id="title107">
			Seleziona i contatti dalla lista sottostante
		    </caption>		    
		    <thead>
			<tr>
			    <td colspan="5" class="pagination">
				<div class="paginator">
				    <span class="prev">
					<a href="javascript: void(0);">&nbsp;</a>
				    </span>
				    <span class="loader">Sto caricando...</span>
				    <span class="next">
					<a href="javascript: void(0);">&nbsp;</a>
				    </span>
				</div>
			    </td>
			</tr>		    
			<tr>
			    <th class="sortable default {ref: 'contact_name'}">Nome</th>
			    <td>&nbsp;</td>
			</tr>
		    </thead>
		    <tbody id="contacts">
			<!-- Questo contenuto verrà rimpiazzato dalla paginazione-->
		    </tbody>
		</table>
	    </li>

	</ul>
    </form>
</div>	
<div id="detailTableRight">
    <form id="form-invia" method="post" action="/admin/location/contatti/id/<?php echo $this->data['location_id']?>">
	<ul>
	    <li id="fo2li107" class="likert col2">
		<table cellspacing="0">
		    <caption id="title107">
			Contatti Selezionati
		    </caption>		    

		    <tbody id="selected_contacts">
			<!-- Questo contenuto verrà rimpiazzato dalla paginazione-->
			<?php
			if(  count( $this->data['location_contacts'] ) ):
			    foreach( $this->data['location_contacts'] AS $contact ) : ?>
			    <tr class="unselectable" id="contact_<?php echo $contact['contact_id'] ?>">
				<th>
				    <span><?php echo $contact['contact_firstname'] ?> <?php echo $contact['contact_lastname'] ?></span>
				    <div class="details">
					<h4><strong>Tel: </strong> <?php echo $contact['contact_phone'] ?></h4>
					<h4><strong>Email: </strong> <?php echo $contact['contact_email'] ?></h4>
				    </div>
				</th>
				<td>
				    <ul>
					<li class="complex">
					    <span class="left">
						<label>Ruolo:</label>
						<select class="field select addr" name="contact_<?php echo $contact['contact_id'] ?>" id="contact_<?php echo $contact['contact_id'] ?>">
						<?php foreach( $this->contact_roles AS $k => $role ) : ?>
						    <option value="<?php echo $k ?>" <?php echo ( $k == $contact['fab_contacts_role'] ) ? 'selected="selected"' : '' ?>><?php echo $role ?></option>
						<?php endforeach; ?>
						</select>
					    </span>
					</li>
				    </ul>
				</td>
				<td title="Operazioni">
				    <span class="actions">
					<a class="del" id="unlink-contact-<?php echo $contact['contact_id']?>" href="#">
					    &nbsp;
					</a>
				    </span>
				</td>
			    </tr>
			    <?php endforeach;
			else:
			    ?><tr class="result"><td colspan="5">Nessun elemento presente...</td></tr> <?php	
			endif;?>			
		    </tbody>
		</table>		
		<input type="hidden" name="conferma" id="conferma" value="conferma" />
	    </li>
	</ul>
    </form>
</div>

<br style="clear: both" />
<form>
    <ul>
	<li class="section">
	    <h3>Oppure:</h3>
	    <ul>
		<li class="addnew">
		    <a id="new" class="button" href="/admin/ajax/form/newcontact?">
			<img src="/images/admin/add-new.png" />Aggiungi Nuovo Contatto (Veloce)
		    </a>
		</li>
	    </ul>
	</li>
    </ul>
</form>
    <div id="formButtons">
	<button id="salva" name="salva" value="salva" class="button positive">
	    <img src="/images/admin/tick.png" alt="" />Salva
	</button>
    </div>	
